# coding:utf-8
#########################
#   Author : Lion yu    #
#   Date : 2025/04/15   #
#   Id : SM2772         #
#########################
import os
from urllib.parse import quote
import json
import time
import hmac
import hashlib
import base64
import urllib.parse
import requests
from handle import Log, DingTalk_AccessToken, DingTalk_Secret, picPath, ProjectConfig
from Notice.ddNotice import *

class ddSendMsg(DDnotices):
    
    def __init__(self):
        super().__init__()
        self.timestamp = str((round(time.time() + 3500) * 1000))
        secret_enc = self.secret.encode('utf-8')
        string_to_sign = f"{self.timestamp}\n{self.secret}"
        string_to_sign_enc = string_to_sign.encode('utf-8')
        hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest()
        self.sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))
        self.webhook = f"{self.webhookURI}?access_token={DingTalk_AccessToken}&timestamp={self.timestamp}&sign={self.sign}"
        